package com.person.leetcode.editor.cn;

import java.util.Arrays;

/**
 * 75.颜色分类
 * 经典的荷兰国旗问题
 * 2022-11-14 14:32:02
 **/
public class Sequence_0075_SortColors {
    public static void main(String[] args) {
        Solution solution = new Sequence_0075_SortColors().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public void sortColors(int[] nums) {
            //头部0指针和尾部2指针
            int p0 = 0, p2 = nums.length - 1;
            for (int i = 0; i <= p2; i++) {
                while (i <= p2 && 2 == nums[i]) {
                    int t = nums[p2];
                    nums[p2] = nums[i];
                    nums[i] = t;
                    p2--;
                }
                if (0 == nums[i]) {
                    int t = nums[p0];
                    nums[p0] = nums[i];
                    nums[i] = t;
                    p0++;
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}